/////////////////////////////////////////////////////////////////////////////
// Name:        variantimage.h
// Purpose:     A variant type supporting an image.
// Author:      Julian Smart
// Modified by:
// Created:     2006-05-11
// RCS-ID:      $$
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_VARIANTIMAGE_H_
#define _WX_VARIANTIMAGE_H_

#include "wx/defs.h"
#include "wx/variant.h"
#include "wx/image.h"

#include "variantutils/variantref.h"

#include "imageutils/imageblock.h"

/*!
 * wxPictureVariantData stores the actual data.
 */

class wxPictureVariantData: public wxClonableVariantData
{
DECLARE_DYNAMIC_CLASS(wxPictureVariantData)
public:

// Construction & destruction

    wxPictureVariantData() {}
    wxPictureVariantData(const wxPictureVariantData& data);
    ~wxPictureVariantData() {}

// OVERRIDEABLES

    /// Clone
    virtual wxVariantData* Clone() { return new wxPictureVariantData(*this); }
    virtual bool Eq(wxVariantData& data) const;
    virtual bool Write(wxString& str) const;
    virtual bool Read(wxString& str);

    // What type is it? Return a string name.
    virtual wxString GetType() const { return wxT("image"); }

// NEW OPERATIONS

    /// Get image block
    wxImageBlock& GetImageBlock() { return m_imageBlock; }
    const wxImageBlock& GetImageBlock() const { return m_imageBlock; }
    void SetImageBlock(const wxImageBlock& imageBlock) { m_imageBlock = imageBlock; }

    /// Set image
    void SetImage(const wxImage& image, int imageType = wxBITMAP_TYPE_JPEG);

    /// Get image
    const wxImage& GetImage() const { return m_image; }
    wxImage& GetImage() { return m_image; }

    /// Ensure image has been created from the data
    bool MakeImage(bool force = false);

private:
    wxImageBlock    m_imageBlock;
    wxImage         m_image;
};

#if 0

/*!
 * wxPictureVariantData: just points to a wxVariantPictureRefData which stores
 * the actual data and is ref-counted;
 */

class wxPictureVariantData: public wxRefCountingVariantData
{
DECLARE_DYNAMIC_CLASS(wxPictureVariantData)
public:

// Construction & destruction

    wxPictureVariantData() {};
    ~wxPictureVariantData() {};

// OVERRIDEABLES

    // What type is it? Return a string name.
    virtual wxString GetType() const { return wxT("image"); }

// NEW OPERATIONS

    /// Get image block
    wxImageBlock& GetImageBlock();
    const wxImageBlock& GetImageBlock() const;

    /// Set image
    void SetImage(const wxImage& image, int imageType = wxBITMAP_TYPE_JPEG);

    /// Get image
    const wxImage& GetImage() const;
    wxImage& GetImage();

    /// Ensure image has been created from the data
    bool MakeImage(bool force = false);

    virtual wxVariantRefData* CreateVariantRefData() { return new wxVariantPictureRefData(); }

    wxVariantPictureRefData* GetImageRefData() const { return (wxVariantPictureRefData*) GetVariantRefData(); }

private:
};

#endif

// Useful functions

// Is this variant an image?
bool wxIsImageVariant(const wxVariant& variant);

// Get the image data
wxPictureVariantData* wxGetImageVariantData(const wxVariant& variant);

// Create image variant
wxVariant wxCreateImageVariant(const wxString& name = wxEmptyString);
wxVariant wxCreateImageVariant(const wxImage& image, const wxString& name = wxEmptyString);
wxVariant wxCreateImageVariant(const wxImageBlock& imageBlock, const wxString& name = wxEmptyString);

#endif
    // _WX_VARIANTIMAGE_H_
